package com.yanqu.road.server.cmd.activity.recallplayer;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.RecallPlayerProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.connect.CrossAgentLinkedControl;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = CrossProtocol.C_PLAYER_RECALL_UPDATE_RETURN_USER_INFO, desc = "区服请求更新回归玩家信息")
public class CrossUpdateBindUserInfoCmd implements Command {
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        RecallPlayerProto.RecallPlayerCrossGetUserInfoReq reqCrossMsg = RecallPlayerProto.RecallPlayerCrossGetUserInfoReq.parseFrom(packet.getBytes());
        RecallPlayerProto.RecallPlayerGetServerUserInfoReq.Builder reqServerMsg = RecallPlayerProto.RecallPlayerGetServerUserInfoReq.newBuilder();
        reqServerMsg.setCrossReq(reqCrossMsg);
        reqServerMsg.setFromUserId(packet.getPlayerId());
        reqServerMsg.setFromUserServer(CrossAgentLinkedControl.getLinkedClient(ctx).getServerId());
        //转发到目标玩家区服
        YanQuMessage message = YanQuMessageUtils.buildMessage(GameProtocol.S_RECALL_PLAYER_UPDATE_USER_INFO_FROM_CROSS, reqServerMsg);
        MessageHelper.sendPacket(reqCrossMsg.getRecallUserServer(), 0, message);

    }
}
